package io.coderyeah.ymcc.mq.consumer;

import com.alibaba.fastjson2.JSON;
import io.coderyeah.ymcc.constant.MQConstants;
import io.coderyeah.ymcc.dto.PayResultMsgInMQ;
import io.coderyeah.ymcc.service.ICourseUserLearnService;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author lqs
 * @date 2022/11/6 15:49
 */
@Component
@RocketMQMessageListener(topic = MQConstants.MQ_PAY_TOPIC,    //topic
        selectorExpression = MQConstants.MQ_PAY_TAGS,         //tags
        consumerGroup = "service-pay-producer",                     //生产者组名字
        messageModel = MessageModel.BROADCASTING)                 //消息的消费模式 CLUSTERING：集群    BROADCASTING：广播
public class PayResultConsumer implements RocketMQListener<MessageExt> {
    @Autowired
    private ICourseUserLearnService learnService;

    @Override
    public void onMessage(MessageExt message) {
        /*
        *   Map<String,Object> map  = new HashMap<>();
            map.put("userId",loginId);
            map.put("courseIds",ids);
        * */

        PayResultMsgInMQ payResultMsgInMQ = JSON.parseObject(message.getBody(), PayResultMsgInMQ.class);
        learnService.updateUserLearn(payResultMsgInMQ);
    }
}
